package com.leigq.www.mybatisplusstudy.domain.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.leigq.www.mybatisplusstudy.domain.entity.Department;
import com.leigq.www.mybatisplusstudy.domain.mapper.DepartmentMapper;
import com.leigq.www.mybatisplusstudy.domain.service.IDepartmentService;
import com.leigq.www.mybatisplusstudy.domain.service.impl.base.MyServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 部门服务实现类
 * </p>
 *
 * @author leigq
 * @since 2019-06-14
 */
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class DepartmentServiceImpl extends MyServiceImpl<DepartmentMapper, Department> implements IDepartmentService {

    /**
     * 查询所有部门
     *
     * @param page the page
     * @return the page
     */
    @Override
    public IPage<Department> listDepartments(Page<Department> page) {
        return super.lambdaQuery().likeRight(Department::getName, "财务").page(page);
    }

    /**
     * 添加部门
     *
     * @return the boolean
     */
    @Override
    public Boolean addDepartments() {
        // 测试自动填充
        Department department = Department.builder()
                .name("部门1")
                .staffNum(3)
                .build();
        return super.save(department);
    }


    /**
     * 修改部门
     *
     * @return the boolean
     */
    @Override
    public Boolean updateDepartments(Long id) {
        // 测试自动填充
        return super.updateById(Department.builder().id(id).name("部门2").build());
    }
}
